package com.alibaba.citrus.cr.service;

import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.bcorder.esdegrade.dto.GetEsDegradeValueResponse;
import com.epoch.app.bcorder.esdegrade.service.EsDegradeService;
import com.epoch.app.bcorder.service.BcOrderService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yifei
 * @since 2022/11/14
 */
@Service
@Primary
public class EsDegradeServiceImpl implements EsDegradeService {

    @Resource
    BcOrderService bcOrderService;

    private final Log log = Log.getLogger(EsDegradeServiceImpl.class);

    @Override
    public GetEsDegradeValueResponse getEsDegradeValue() {
        try {
            GetEsDegradeValueResponse esDegradeValueResponse = new GetEsDegradeValueResponse();
            com.epoch.app.bcorder.model.dto.GetEsDegradeValueResponse esDegradeValue = bcOrderService.getEsDegradeValue();
            if (esDegradeValue != null && Boolean.TRUE.toString().equals(esDegradeValue.getValue())) {
                esDegradeValueResponse.setResult(Boolean.TRUE);
                return esDegradeValueResponse;
            }
            esDegradeValueResponse.setResult(Boolean.FALSE);
            return esDegradeValueResponse;
        } catch (Exception e) {
            log.error("EsDegradeServiceImpl.getEsDegradeValue.error:" + e);
            GetEsDegradeValueResponse esDegradeValueResponse = new GetEsDegradeValueResponse();
            esDegradeValueResponse.setResult(Boolean.FALSE);
            return esDegradeValueResponse;
        }
    }
}
